﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace DAO
{
    public class CDataProvider
    {
        // Chuoi ket noi toi CSDL -- file CSDL de trong thu muc bin
        string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=QLKS.mdb";

        // Ham select du lieu
        public DataTable DocDuLieu(String QueryString)
        {
            OleDbConnection conn = new OleDbConnection(ConnectionString);
            conn.Open();

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            try
            {
                OleDbDataAdapter adapter = new OleDbDataAdapter(QueryString, conn);
                adapter.Fill(ds);

                dt = ds.Tables[0];

            }
            catch (System.Exception)
            {

            }
            conn.Close();

            return dt;
        }

        // Ham thuc thi du lieu : insert , update , delete
        public Boolean ThucThiDuLieu(String CommandString)
        {
            Boolean kq = false;

            OleDbConnection conn = new OleDbConnection(ConnectionString);
            conn.Open();

            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = CommandString.ToString();
            cmd.CommandType = CommandType.Text;

            // Neu insert thanh cong
            if(cmd.ExecuteNonQuery() > 0)
                kq = true;

            cmd.Dispose();
            conn.Close();

            return kq;
        }
      
    }
}
